﻿namespace SimpleWebServices.Web.Mvc
{
    using System;
    using System.Collections.Specialized;
    using System.Net;
    using System.Web;
    using System.Web.Mvc;
    using Moq;
    using Xunit;

    public sealed class NotFoundResultFacts
    {
        [Fact]
        public void typedef()
        {
            Assert.True(new ObjectExpectations<NotFoundResult>()
                .DerivesFrom<ActionResult>()
                .IsConcreteClass()
                .IsSealed()
                .HasDefaultConstructor()
                .Result);
        }

        [Fact]
        public void ctor()
        {
            Assert.NotNull(new NotFoundResult());
        }

        [Fact]
        public void op_ExecuteResult_ControllerContextNull()
        {
            Assert.Throws<ArgumentNullException>(() => new NotFoundResult().ExecuteResult(null as ControllerContext));
        }

        [Fact]
        public void op_ExecuteResult_ControllerContext()
        {
            var mock = new Mock<HttpContextBase>();
            mock.SetupGet<string>(x => x.Request.HttpMethod).Returns("GET").Verifiable();
            mock.SetupGet<Uri>(x => x.Request.Url).Returns(new Uri("http://example.com/path?query")).Verifiable();
            mock.SetupGet<NameValueCollection>(x => x.Request.Headers).Returns(new NameValueCollection { { "Accept", "*/*" } }).Verifiable();
            mock.Setup(x => x.Response.Cache.SetCacheability(HttpCacheability.Public)).Verifiable();
            mock.Setup(x => x.Response.Cache.SetExpires(It.IsAny<DateTime>())).Verifiable();
            mock.SetupSet(x => x.Response.StatusCode).Callback(expected => Assert.Equal<int>((int)HttpStatusCode.NotFound, expected)).Verifiable();

            new NotFoundResult().ExecuteResult(new ControllerContext()
            {
                HttpContext = mock.Object
            });

            mock.VerifyAll();
        }
    }
}